package es.ucm.fdi.isbc.viviendas.funciones_similitud;


import es.ucm.fdi.isbc.viviendas.representacion.ExtrasBasicos;
import jcolibri.exception.NoApplicableSimilarityFunctionException;
import jcolibri.method.retrieve.NNretrieval.similarity.LocalSimilarityFunction;


public class SimExtrasBasicos implements LocalSimilarityFunction {
	
	
	@Override
	public double compute(Object caseObject, Object queryObject)
			throws NoApplicableSimilarityFunctionException {
		//Si los dos objetos son null se devuelve 0
		if ((caseObject == null) || (queryObject == null))
			return 0;
		if (!(caseObject instanceof ExtrasBasicos))
			throw new jcolibri.exception.NoApplicableSimilarityFunctionException(this.getClass(), caseObject.getClass());
		if (!(queryObject instanceof ExtrasBasicos))
			throw new jcolibri.exception.NoApplicableSimilarityFunctionException(this.getClass(), queryObject.getClass());

		return (simExtras((ExtrasBasicos)caseObject,(ExtrasBasicos)queryObject));
		
	}


	private double simExtras(ExtrasBasicos caso, ExtrasBasicos query) {
		double sim=0.0;
		double sumSim=9.0; 
		//Calculamos la similitud sumando con distinto peso
		if(caso.isAireAcondicionado()==query.isAireAcondicionado()) sim = sim + 0.8;
		if(caso.isAmueblado()==query.isAmueblado()) sim = sim + 0.7;
		if(caso.isArmarios()==query.isArmarios()) sim = sim + 0.7;
		if(caso.isCalefaccion()==query.isCalefaccion()) sim = sim + 0.6;
		if(caso.isCocinaOffice()==query.isCocinaOffice()) sim = sim + 0.3;
		if(caso.isDomotica()==query.isDomotica()) sim = sim + 1;
		if(caso.isElectrodomesticos()==query.isElectrodomesticos()) sim = sim + 0.4;
		if(caso.isGresCeramica()==query.isGresCeramica()) sim = sim + 0.3;
		if(caso.isHorno()==query.isHorno()) sim = sim + 0.4;
		if(caso.isInternet()==query.isInternet()) sim = sim + 0.2;
		if(caso.isLavadero()==query.isLavadero()) sim = sim + 0.1;
		if(caso.isLavadora()==query.isLavadora()) sim = sim + 0.3;
		if(caso.isMicroondas()==query.isMicroondas()) sim = sim + 0.2;
		if(caso.isNevera()==query.isNevera()) sim = sim + 0.5;
		if(caso.isParquet()==query.isParquet()) sim = sim + 0.6;
		if(caso.isPuertaBlindada()==query.isPuertaBlindada()) sim = sim + 0.8;
		if(caso.isSuiteConBanio()==query.isSuiteConBanio()) sim = sim + 0.8;
		if(caso.isTv()==query.isTv()) sim = sim + 0.3;
		//Dividimos la suma por el total
		return (double)((double)sim/(double)sumSim);
	}


	@Override
	public boolean isApplicable(Object caseObject, Object queryObject) {
		//Comprobamos que los objetos son ExtrasBasicos o null
		if((caseObject==null)&&(queryObject==null))
			return true;
		else if(caseObject==null)
			return queryObject instanceof ExtrasBasicos;
		else if(queryObject==null)
			return caseObject instanceof  ExtrasBasicos;
		else
			return (caseObject instanceof  ExtrasBasicos)&&(queryObject instanceof  ExtrasBasicos);

	}

}